package com.woniuxy.microgoodsserver.goodmag.mapper;

import com.woniuxy.microcommonserver.bean.gy.GoodsAttributesInfo;
import com.woniuxy.microcommonserver.bean.gy.GoodsInfo;
import org.apache.ibatis.annotations.*;

import java.util.List;
import java.util.Map;

/**
    商品管理
 * @params:
 * @return
 */
@Mapper
public interface GoodMapper {
    /**
        添加商品
     * @params:
     * @return
     */
    @Options(useGeneratedKeys = true,
            keyProperty = "g.id",
            keyColumn = "id"
    )
    @Insert("insert into goods_info(goods_name,brand_info_id,show_content,page_title," +
            "keyword,page_keyword,page_desc,good_details,after_server,set_goods,is_up,status,good_category_info2_id," +
            "warn_stock,integral) values(#{g.goodsName},#{g.brandInfoId},#{g.showContent},#{g.pageTitle},#{g.keyword}," +
            "#{g.pageKeyword},#{g.pageDesc},#{g.goodDetails},#{g.afterServer} ,#{g.setGoods},#{g.isUp},0" +
            ",#{g.goodCategoryInfo2Id},#{g.warnStock},#{g.integral})")
    public int addGood(@Param("g") GoodsInfo goodsInfo);


    /**
        添加商品sku
     * @params:
     * @return
     */
    @Insert("insert into goods_attributes_info(goods_attributes_list,stock,cost_price,goods_info_id,good_display_image," +
            "market_price,sales_price,status) values(#{e.goodsAttributesList},#{e.stock},#{e.costPrice}," +
            "#{goodsId},#{e.goodDisplayImage},#{e.marketPrice},#{e.salesPrice},0)")
    public void addGoodsAttributesInfos(@Param("e") GoodsAttributesInfo e, @Param("goodsId")Integer goodsId);


    /**
     查询所有商品信息
     * @params:
     * @return
     */
    public List<Map> findAllGoods(@Param("g") GoodsInfo goodsInfo);

    /**
     根据ID删除商品信息
     * @params:
     * @return
     */
    @Update("update goods_attributes_info set status=1 where id = #{id}")
    public void deleteGood(Integer id);

    /**
     修改商品信息包括Sku属性
     * @params:
     * @return
     */
    public void updateAttribute(@Param("g") GoodsAttributesInfo goodsAttributesInfo);


    /**
        修改商品信息
     * @params:
     * @return
     */
    public void updateGood(@Param("g") GoodsInfo goodsInfo);

    /**
     根据ID查询商品名
     * @params:
     * @return
     */
    @ResultType(GoodsInfo.class)
    @Select("select goods_name goodsName from goods_info where id = #{id}")
    public GoodsInfo findGoodById(Integer id);
}
